package com.zrentech.order.data.dbhelper.builder;

import android.content.ContentValues;
import android.database.Cursor;

import com.zrentech.order.data.busibean.OrderBean;
import com.zrentech.order.data.dbhelper.DatabaseBuilder;

/**
 * 
 * 提供关于订单的创建和解析方面的功能
 * 
 * @author Leon
 */

public class OrderDBuilder extends DatabaseBuilder<OrderBean> {

	public static final String TRACK_ID = "id";
	public static final String TRACK_ORDERTIME = "orderTime";
	public static final String TRACK_USERID = "userID";
	public static final String TRACK_TABLEID = "tableID";
	public static final String TRACK_PERSONNUM = "personNum";
	public static final String TRACK_ISPAY = "isPay";
	public static final String TRACK_REMARK = "remark";

	@Override
	public OrderBean build(Cursor query) {

		int columnId = query.getColumnIndex(TRACK_ID);
		int columnOrderTime = query.getColumnIndex(TRACK_ORDERTIME);
		int columnUserID = query.getColumnIndex(TRACK_USERID);
		int columnTableID = query.getColumnIndex(TRACK_TABLEID);
		int columnPersonNum = query.getColumnIndex(TRACK_PERSONNUM);
		int columnIsPay = query.getColumnIndex(TRACK_ISPAY);
		int columnRemark = query.getColumnIndex(TRACK_REMARK);

		OrderBean order = new OrderBean();
		order.setId(query.getInt(columnId));
		order.setOrderTime(query.getString(columnOrderTime));
		order.setUserID(query.getInt(columnUserID));
		order.setTableID(query.getInt(columnTableID));
		order.setPersonNum(query.getInt(columnPersonNum));
		order.setIsPay(query.getInt(columnIsPay));
		order.setRemark(query.getString(columnRemark));

		return order;
	}

	@Override
	public ContentValues deconstruct(OrderBean track) {
		ContentValues values = new ContentValues();
		values.put(TRACK_ID, track.getId());
		values.put(TRACK_ORDERTIME, track.getOrderTime());
		values.put(TRACK_USERID, track.getUserID());
		values.put(TRACK_TABLEID, track.getTableID());
		values.put(TRACK_PERSONNUM, track.getPersonNum());
		values.put(TRACK_ISPAY, track.getIsPay());
		values.put(TRACK_REMARK, track.getRemark());
		return values;
	}

}
